package com.asiainfo.integration.tibco;

import javax.jms.*;

public class ConsumerMessageListener implements MessageListener {

    public void onMessage(Message message) {

        if (message instanceof javax.jms.TextMessage) {
            TextMessage textMsg = (TextMessage) message;
            try {
                System.out.println("The receiver received a message:" + textMsg.getText());
            } catch (JMSException e) {
                e.printStackTrace();
            }
        } else if (message instanceof javax.jms.StreamMessage) {
            StreamMessage streamMsg = (StreamMessage) message;
            try {
                int length = message.getIntProperty("length");
                byte[] content = new byte[length];
                if (streamMsg.readBytes(content) > 0) {
                    String str = new String(content);
                    System.out.println("The message length is:" + length);
                    System.out.println("The receiver received a message:" + str);
                }
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }
    }
}
